<?php
/**
 * 后台新闻处理程序
 *
 * Created	  	: 2011-10-10
 * Modified   	: 2011-10-10
 * @link		: http://www.fqeat.com
 * @copyright	: (C) 2011
 * @version	: 0.1.0
 * @author		: Joseph Chen (jsph.chen@gmail.com)
 */
switch ($do) {
	
	case 'categorySave':
		$_POST['id'] = (int)$_POST['id'];
		if ($_POST['id']) {
			$ret = News::modifyCategory($_POST['id'], $_POST['name'], $_POST['lang']);
		} else {
			$ret = News::addCategory($_POST['name'], $_POST['lang']);
		}
		if (!$ret) {
			$type = 'Failure';
			$desc = App::msg();
		}
		$redirctMo = 'newsCategoryList';
		break;
	
	case 'categoryDelete':
		$_GET['id'] = (int)$_GET['id'];
		$ret = News::deleteCategory($_GET['id']);
		if (!$ret) {
			$type = 'Failure';
			$desc = App::msg();
		}
		$redirctMo = 'newsCategoryList';
		break;
	
	case 'save':
		$_POST['id'] = (int)$_POST['id'];
		if ($_POST['id']) {
			$ret = News::modify(
						$_POST['id'], 
						$_POST['cid'], 
						$_POST['title'], 
						$_POST['content'], 
						$_POST['lang']
			);
		} else {
			$ret = News::add(
						$_POST['cid'], 
						$_POST['title'], 
						$_POST['content'], 
						$_POST['lang']
			);
		}
		if (!$ret) {
			$type = 'Failure';
			$desc = $GLOBALS['LFailure'];
			exit;
		}
		break;
	
	case 'delete':
		$_GET['id'] = (int)$_GET['id'];
		$ret = News::delete($_GET['id']);
		if (!$ret) {
			$type = 'Failure';
			$desc = $GLOBALS['LFailure'];
		}
		$redirctMo = 'newsList';
		break;
		
	case 'getCategoryList':
		if (!empty($_GET['lang'])) {
			$lang = $_GET['lang'];
		}
		$categoryList = News::getCategoryList($lang);
		if (!empty($_GET['ajax'])) {
			echo json_encode($categoryList);
			exit;
		}
		break;

	default:
		$type = 'Error';
		$desc = $GLOBALS['LUnknowRequest'];
		break;
		
}
$g_msg = array(
	'type' => isset($type) ? $type : 'Success',
	'desc' => isset($desc) ? $desc : $GLOBALS['LSuccess'],
);
if (empty($redirctMo)) {
	$redirctMo = 'newsList';
}
empty($r_url) && $r_url = '?block=news&mo='.$redirctMo;
